package com.jiangyao.service.impl;

import com.jiangyao.common.utils.FtpClient;
import com.jiangyao.model.dto.UserDto;
import com.jiangyao.model.entity.PublicProgress;
import com.jiangyao.dao.IPublicProgressDao;
import com.jiangyao.model.vo.PublicSubjectListVo;
import com.jiangyao.service.PublicProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 学习进度表 服务实现类
 * </p>
 *
 * @author lijing
 * @since 2021-01-19
 */
@Service
public class PublicProgressServiceImpl extends BaseServiceImpl<IPublicProgressDao, PublicProgress> implements PublicProgressService {

    @Autowired
    private IPublicProgressDao publicProgressDao;

    @Override
    public List<PublicSubjectListVo> getUserPublicSubject() {
        UserDto dto = new UserDto();
        dto.setUserId(getLoginApiUserId());
        List<PublicSubjectListVo> result = publicProgressDao.getUserPublicSubject(dto);
        if (CollectionUtils.isEmpty(result)) {
            return result;
        }
        result.forEach(r -> r.setCoverFull(FtpClient.fullFtpUrl(r.getCover())));
        return result;
    }
}
